google.load('visualization', '1', {packages:['table']});


// final function that builds the market table from the json object
function drawMarketTable(marketTableResp0) 
{
    var marketTableResp = eval('(' + marketTableResp0.responseText + ')'); 
	var data = new google.visualization.DataTable();
	data.addColumn('string', 'Asset');
	data.addColumn('number', 'Market Price (c$)');
	data.addRows(marketTableResp.viewList.length);
	for (var i = 0; i < marketTableResp.viewList.length; i++)
	{
		data.setCell(i, 0, marketTableResp.viewList[i].assetName );
		data.setCell(i, 1, marketTableResp.viewList[i].view);
	}

	var table = new google.visualization.Table(document.getElementById('marketTable_div'));	
	table.draw(data, {width: 300, height: 300, title: 'Market Prices'});
}

var updateMarketTable = function() 
{
    var args = { type:"get", url:"/json/getMarketView/", complete:drawMarketTable };
    $.ajax(args);
    return false;
};

$(document).ready( function() 
{
    updateMarketTable();
});
    
